package com.yanzhu.service.mapper;

import com.yanzhu.service.model.Wallet;
import org.apache.ibatis.annotations.*;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 9:59 2018/1/19
 * @Modified:
 */
@Mapper
public interface WalletMapper {
    @Insert("insert into wallet(uid, balance) values(#{uid}, #{balance})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = long.class)
    int insert(Wallet wallet);

    @Select("select * from wallet where uid = #{uid}")
    Wallet selectByUid(@Param("uid") long uid);

    @Select("select * from wallet where uid = #{uid}")
    Wallet selectBalanceByUid(@Param("uid") long uid);

    @Update("update wallet" +
            "  set balance=balance - #{money}" +
            "  where uid = #{uid}")
    void update(@Param("uid") long uid, @Param("money") float money);

    @Update("update wallet" +
            "  set balance=balance + #{money}" +
            "  where uid = #{uid}")
    void updateAfterGrabPackets(@Param("uid") long uid, @Param("money") float money);

    @Update("update wallet" +
            "  set balance=balance + #{fee}" +
            "  where uid = #{uid}")
    void updateAfterRecharge(@Param("uid") long uid, @Param("fee") float fee);
}
